  
#include "copyright.h"
#include "virtualmem.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
VirtualMem::VirtualMem()
{
 fd = open("VMFile.dat", O_RDWR|O_CREAT|O_TRUNC, 0);
 bm=new BitMap(NumVMPages);
}

 VirtualMem::~VirtualMem()
{
 //delete bm;
}

 int VirtualMem::Find()
{
 return bm->Find();
}

 void VirtualMem::Mark(int which)
{
 bm->Mark(which);
}

 void VirtualMem::Clear(int which)
{
 bm->Clear(which);
}

 bool VirtualMem::Test(int which)
{
 return bm->Test(which);
}

 int VirtualMem::NumClear()
{
 return bm->NumClear();
}

 bool VirtualMem::Read(int PageNum,char* buffer)//将页面标号为PageNum的页面读出至buffer
{
 lseek(fd,PageNum*PageSize,SEEK_SET);
 read(fd,buffer,PageSize);
 return true;
}

 bool VirtualMem::Write(int PageNum,char* buffer)//将buffer写入PageNum页面
{
 lseek(fd,PageNum*PageSize,SEEK_SET);
 write(fd,buffer,PageSize);
 return true;
}

